package com.sharedlease.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sharedlease.entity.Indent;
import com.sharedlease.entity.R;
import com.sharedlease.service.IndentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import java.sql.Wrapper;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 吴钟富
 * @since 2021-03-02
 */
@RestController
@Api(tags = "订单相关接口")
@RequestMapping("/indent")
public class IndentController {
    @Autowired
    public IndentService indentService;

    @GetMapping("/getById/{id}")
    @ApiOperation("根据一个id查询订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要查询的订单id", defaultValue = "1"),

    }
    )
    public Indent getById(@PathVariable Long id) {
        Indent indent = indentService.getById(id);
        return indent;
    }

    @GetMapping("/list")
    @ApiOperation("查询全部订单")
    public List<Indent> list() {
        List<Indent> list = indentService.list(null);
        return list;
    }

    @PostMapping("/save")
    @ApiOperation("新增一条订单")
    public R save(@RequestBody Indent indent) {

        return R.operate(indentService.save(indent));
    }

    @PutMapping("/update")
    @ApiOperation("根据id更改一条订单")
    R update(@RequestBody Indent indent) {
        if (indentService.updateById(indent)) {
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/removeById/{id}")
    @ApiOperation("根据id删除一条订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要删除的订单id", defaultValue = "-1"),

    }
    )
    R removeById(@PathVariable Long id) {

        return R.operate(indentService.removeById(id));
    }

    @GetMapping("/getByMid/{mid}")
    @ApiOperation("根据mid查询订单")
    public List<Indent> getByMid(@PathVariable Long mid) {
        QueryWrapper<Indent> wrapper = new QueryWrapper<>();
        wrapper.eq("mid", mid);
        List<Indent> list = indentService.list(wrapper);
        return list;
    }

    @GetMapping("/getByUid/{uid}")
    @ApiOperation("根据uid查询订单")
    public List<Indent> getByUid(@PathVariable Long uid) {
        QueryWrapper<Indent> wrapper = new QueryWrapper<>();
        wrapper.eq("uid", uid);
        List<Indent> list = indentService.list(wrapper);
        return list;
    }


}
//@RestController
//@Api(tags = "用户管理相关接口")
//@RequestMapping("/user")
//public class UserController {
//
//    @PostMapping("/")
//    @ApiOperation("添加用户的接口")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "username", value = "用户名", defaultValue = "李四"),
//            @ApiImplicitParam(name = "address", value = "用户地址", defaultValue = "深圳", required = true)
//    }
//    )
//    public RespBean addUser(String username, @RequestParam(required = true) String address) {
//        return new RespBean();
//    }
//
//    @GetMapping("/")
//    @ApiOperation("根据id查询用户的接口")
//    @ApiImplicitParam(name = "id", value = "用户id", defaultValue = "99", required = true)
//    public User getUserById(@PathVariable Long id) {
//        User user = new User();
//        user.setId(id);
//        return user;
//    }
//    @PutMapping("/{id}")
//    @ApiOperation("根据id更新用户的接口")
//    public User updateUserById(@RequestBody User user) {
//        return user;
//    }
//}


